package no.hig.ekm.ircclient;

import java.util.Locale;
import java.util.ResourceBundle;

import jerklib.Profile;

/* 
 * Plan:
 * 
 * Regler:
 *  - Enn commit skal v�re kj�rbar
 *  - Fornuftige kommentarer p� commit
 *  - Fornuftig kommentering i kode og javadoc
 * 
 * Todo-liste
 *  - User feedback if connection gets lost while connectiong
 *  -- Eigil foreslår å vise serverMessage vinduet før CONNECTION_COMPLETE:
 *  - List of available channels						(kristofers)
 *  - Flashe kanaler med endringer i treet				(kristofers)
 *  - KanalGUI											(eigil)			(done)
 *  - Håndtere usynlig pålogging til server				(eigil)			(done)
 *  - Slap/whois										(eigil)			(done)
 *  - Håndtere ERROR events								(eigil)			(done?)
 *  - Vise nick-prefix i chat-vinduet					(eigil)			(done)
 *  - Oversette til Norsk (Og fikse glemte stringer)	(morten)		(done)
 *  - (hjelpesystem)
 * 
 *  Rapporten:
 *   - Hvordan virker klienten
 *   -- Forklaring av connect
 *   -- Forklaring av vindussystemet
 *   -- Forklaring av Treet
 *   
 *  
 * Klassestruktur:
 * 	- Main (Starter og styrer alt)
 *  --- Internasjonalisering
 *  
 * 	- MainWindow extends JFrame		(MDI-hovedvindu)
 *  - Toolbar
 *  - Meny
 *  (- Statusbar)
 * 
 *  - ConnectionWindow				(MDI internvindu)
 *  - ChannelWindow					(MDI internvindu)
 *  - diverse SettingWindow			(MDI internvindu)
 *  
 */

/**
 * This is the main class which starts the MainWindow
 * 
 * @author eigil, morten, kristofers
 */
public class Main {
	
	public static Locale currentLocale;
	public static ResourceBundle messages;
	
	public static MainWindow win;
	public static ConnectionManagement cm;
	public static FontSelector[] fontSelectors;

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		// Determine locale settings, either by command line arguments, or by
		// the system settings.
		if (args.length == 2)
			currentLocale = new Locale(args[0], args[1]);
		else if (args.length == 1)
			currentLocale = new Locale(args[0]);
		else
			currentLocale = Locale.getDefault();

		// Load the correct language file
		messages = ResourceBundle.getBundle("Irc", currentLocale);

		// Assigning messages to classes
		FontSelector.setMessages(messages);
		ConnectionDialog.setMessages(messages);
		ChannelWindow.setMessages(messages);
		ServerEventListener.setMessages(messages);
		ConnectionManagement.setMessages(messages);
		MainMenu.setMessages(messages);
		ServerSettings.setMessages(messages);
		Fonts.setMessages(messages);
//		AddEditDialog.setMessages(messages);
		MainChannelTree.setMessages(messages);
		MainToolbar.setMessages(messages);
//		MainWindow.setMessages(messages);
		
		/*
		 * Set the Nimbus look and feel If Nimbus (introduced in Java SE 6) is
		 * not available, stay with the default look and feel. For details see
		 * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
					.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException | InstantiationException
				| IllegalAccessException
				| javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		}

		Fonts.init();
		
		/* Create and display the form (according to best practices) */
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				win = new MainWindow();
				cm = new ConnectionManagement();
			}
		});
	}
}